home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / test / string.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  4.1 KB  |  130 lines  |  [TEXT/R*ch]

  1. (* test/string.sml 
  2.    PS 1994-12-10, 1995-06-14 *)
  3.  
  4. use "auxil.sml";
  5.  
  6. local 
  7.     open Char String
  8.  
  9.     val s1 = ""                (* size s1 =  0 *)
  10.     and s2 = "ABCDE\tFGHI";        (* size s2 = 10 *)
  11.     val ABCDE = List.map chr [65,66,67,68,69];  
  12. in
  13.  
  14. val test1 = check'(fn _ => (size s1 = 0 andalso size s2 = 10));
  15. val test2 = check'(fn _ => (sub(s2,6) = chr 70 andalso sub(s2,9) = chr 73));
  16. val test3 = (sub(s1, 0)  seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  17. val test4 = (sub(s2, ~1) seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  18. val test5 = (sub(s2, 10) seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  19.  
  20. val test6 = 
  21.     check'(fn _ => 
  22.        "" = concat [] andalso "" = concat [s1] 
  23.        andalso s2 = concat [s2] andalso s2^s2 = concat [s2,s2]
  24.        andalso "ABCD" = concat ["A","B","C","D"]);
  25.     
  26. val test7 = check'(fn _ => "A" = str(chr 65));
  27.  
  28. val test8 = 
  29.     check'(fn _ => 
  30.        "" = implode [] andalso "ABCDE" = implode ABCDE); 
  31.  
  32. val test9 = 
  33.     check'(fn _ => 
  34.        [] = explode "" andalso ABCDE = explode "ABCDE");
  35.  
  36. val test10 = 
  37.     check'(fn _ => 
  38.        s1 < s2 andalso s1 <= s1 
  39.        andalso s2 > s1 andalso s2 >=s2);
  40.  
  41. val test11a = 
  42.     check'(fn _ => 
  43.        s2 = extract(s2, 0, SOME (size s2))
  44.        andalso s2 = extract(s2, 0, NONE)
  45.        andalso "" = extract(s2, size s2, SOME 0)
  46.        andalso "" = extract(s2, size s2, NONE)
  47.        andalso "" = extract(s1, 0, SOME 0)
  48.        andalso "" = extract(s1, 0, NONE));
  49.  
  50. val test11b = (extract(s2, ~1, SOME 0) seq "WRONG") 
  51.               handle Subscript => "OK" | _ => "WRONG";
  52. val test11c = (extract(s2, 11, SOME 0) seq "WRONG") 
  53.               handle Subscript => "OK" | _ => "WRONG";
  54. val test11d = (extract(s2, 0, SOME 11) seq "WRONG") 
  55.               handle Subscript => "OK" | _ => "WRONG";
  56. val test11e = (extract(s2, 10, SOME 1) seq "WRONG") 
  57.               handle Subscript => "OK" | _ => "WRONG";
  58. val test11f = (extract(s2, ~1, NONE) seq "WRONG") 
  59.               handle Subscript => "OK" | _ => "WRONG";
  60. val test11g = (extract(s2, 11, NONE) seq "WRONG") 
  61.               handle Subscript => "OK" | _ => "WRONG";
  62.  
  63. val test11h = 
  64.     check'(fn _ => 
  65.        "ABCDE" = extract(s2, 0, SOME 5)
  66.        andalso "FGHI" = extract(s2, 6, SOME 4)
  67.        andalso "FGHI" = extract(s2, 6, NONE));
  68.  
  69. val test12a = 
  70.     check'(fn _ => 
  71.        s2 = substring(s2, 0, size s2)
  72.        andalso "" = substring(s2, size s2, 0)
  73.        andalso "" = substring(s1, 0, 0));
  74.  
  75. val test12b = (substring(s2, ~1, 0) seq "WRONG") 
  76.               handle Subscript => "OK" | _ => "WRONG";
  77. val test12c = (substring(s2, 11, 0) seq "WRONG") 
  78.               handle Subscript => "OK" | _ => "WRONG";
  79. val test12d = (substring(s2, 0, 11) seq "WRONG") 
  80.               handle Subscript => "OK" | _ => "WRONG";
  81. val test12e = (substring(s2, 10, 1) seq "WRONG") 
  82.               handle Subscript => "OK" | _ => "WRONG";
  83.  
  84. val test12f = 
  85.     check'(fn _ => 
  86.        "ABCDE" = substring(s2, 0, 5)
  87.        andalso "FGHI" = substring(s2, 6, 4));
  88.  
  89. val test13a = 
  90.     check'(fn _ => 
  91.        (translate (fn _ => "") s2 = ""
  92.         andalso translate (fn x => str x) "" = ""
  93.         andalso translate (fn x => str x) s2 = s2));
  94.  
  95. val test13b = 
  96.     check'(fn _ => 
  97.        (translate (fn c => if c = #"\t" then "XYZ " else str c) s2 
  98.                   = "ABCDEXYZ FGHI"));
  99.  
  100. val test14 = 
  101.     check'(fn _ => 
  102.        (tokens isSpace "" = []
  103.         andalso tokens isSpace "   \t \n" = []
  104.         andalso tokens (fn c => c = #",") ",asd,,def,fgh" 
  105.                 = ["asd","def","fgh"]));
  106.  
  107. val test15 = 
  108.     check'(fn _ => 
  109.        (fields isSpace "" = [""]
  110.         andalso fields isSpace "   \t \n" = ["","","","","","",""]
  111.         andalso fields (fn c => c = #",") ",asd,,def,fgh" 
  112.                 = ["","asd","","def","fgh"]));
  113.  
  114. val test16a = 
  115.     check'(fn _ => 
  116.        EQUAL = compare(s1,s1) andalso EQUAL = compare(s2,s2)
  117.        andalso LESS = compare("A", "B")
  118.        andalso GREATER = compare("B", "A")
  119.        andalso LESS = compare("ABCD", "ABCDE")
  120.        andalso GREATER = compare("ABCDE", "ABCD"));
  121.  
  122. val test16b = 
  123.     check'(fn _ => 
  124.        EQUAL = compare(s1,s1) andalso EQUAL = compare(s2,s2)
  125.        andalso LESS = compare("A", "a")
  126.        andalso GREATER = compare("b", "B")
  127.        andalso LESS = compare("abcd", "abcde")
  128.        andalso GREATER = compare("abcde", "abcd"));
  129. end
  130.